package org.films.domain;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.Table;
import javax.persistence.UniqueConstraint;
import org.springframework.roo.addon.javabean.RooJavaBean;
import org.springframework.roo.addon.tostring.RooToString;
import org.springframework.roo.addon.entity.RooEntity;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Min;
import java.util.Set;
import org.films.domain.Comment;
import java.util.HashSet;
import javax.persistence.ManyToMany;
import javax.persistence.CascadeType;

@Entity
@Table(name = "Users", uniqueConstraints = @UniqueConstraint(columnNames = "username"))
@RooJavaBean
@RooToString
@RooEntity(finders = { "findConsumersByComments" })
public class Consumer {

    @NotNull
    private String username;

    @NotNull
    private String email;

    @NotNull
    private String city;

    @NotNull
    private String street;

    @NotNull
    private String firstName;

    @NotNull
    private String lastName;

    @Min(100000L)
    private Long icq;

    @NotNull
    private String password;

    @ManyToMany(cascade = CascadeType.ALL, mappedBy = "consumer", fetch=FetchType.EAGER)
    private Set<Comment> comments = new HashSet<Comment>();       
}
